# Copyright 2010-2014 David "Alemarius Nexus" Lerch
# 
# This file is part of gtatxd.
#
# gtatxd is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# gtatxd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with gtatxd.  If not, see <http://www.gnu.org/licenses/>.

# Additional permissions are granted, which are listed in the file
# GPLADDITIONS.


CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(prj-gtatxd C CXX)

INCLUDE(CheckSymbolExists)

ADD_SUBDIRECTORY(src)

IF(NOT TARGET nxcommon)
    FIND_PACKAGE(Libnxcommon REQUIRED CONFIG)
ENDIF()

IF(NOT TARGET gtaformats)
    FIND_PACKAGE(Libgtaformats REQUIRED CONFIG)
ENDIF()


IF(GTAFORMATS_ENABLE_SQUISH)
    FIND_PACKAGE(Libsquish REQUIRED)
ENDIF(GTAFORMATS_ENABLE_SQUISH)

IF(GTAFORMATS_ENABLE_PVRTEXLIB)
    FIND_PACKAGE(PVRTexLib REQUIRED)
ENDIF(GTAFORMATS_ENABLE_PVRTEXLIB)

FIND_PACKAGE(PNG REQUIRED)

IF(APPLE)
    FIND_PATH(ICONV_INCLUDE_DIRS iconv.h)
    FIND_LIBRARY(ICONV_LIBRARIES NAMES iconv libiconv)
ENDIF(APPLE)

#SET(GTAFORMATS_CONFIG_H_FOUND "")
#
#FOREACH(_LIB_PATH ${LIBGTAFORMATS_INCLUDE_DIRS})
#	IF(EXISTS "${_LIB_PATH}/gtaformats/config.h")
#		CHECK_SYMBOL_EXISTS(GTAFORMATS_ENABLE_SQUISH "${_LIB_PATH}/gtaformats/config.h" GTAFORMATSENABLESQUISH)
#		CHECK_SYMBOL_EXISTS(GTAFORMATS_ENABLE_PVRTEXLIB "${_LIB_PATH}/gtaformats/config.h" GTAFORMATSENABLEPVRTEXLIB)
#		SET(GTAFORMATS_ENABLE_SQUISH ${GTAFORMATSENABLESQUISH})
#		SET(GTAFORMATS_ENABLE_PVRTEXLIB ${GTAFORMATSENABLEPVRTEXLIB})
#		SET(GTAFORMATS_CONFIG_H_FOUND "1")
#		BREAK()
#	ENDIF(EXISTS "${_LIB_PATH}/gtaformats/config.h")
#ENDFOREACH(_LIB_PATH)
#
#IF(NOT GTAFORMATS_CONFIG_H_FOUND)
#	MESSAGE(SEND_ERROR "config.h of libgtaformats was not found!")
#ENDIF(NOT GTAFORMATS_CONFIG_H_FOUND)

SET(LIBRARIES nxcommon gtaformats)
SET(INCLUDES "")

IF(GTAFORMATS_ENABLE_SQUISH)
    SET(LIBRARIES ${LIBRARIES} "${LIBSQUISH_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${LIBSQUISH_INCLUDE_DIRS}")
ENDIF(GTAFORMATS_ENABLE_SQUISH)

IF(GTAFORMATS_ENABLE_PVRTEXLIB)
    SET(LIBRARIES ${LIBRARIES} "${PVRTEXLIB_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${PVRTEXLIB_INCLUDE_DIRS}")
ENDIF(GTAFORMATS_ENABLE_PVRTEXLIB)

SET(LIBRARIES ${LIBRARIES} "${PNG_LIBRARIES}")
SET(INCLUDES ${INCLUDES} "${PNG_INCLUDE_DIR}")

IF(APPLE)
    SET(LIBRARIES ${LIBRARIES} "${ICONV_LIBRARIES}")
    SET(INCLUDES ${INCLUDES} "${ICONV_INCLUDE_DIRS}")
ENDIF(APPLE)

ADD_EXECUTABLE(gtatxd ${SRCS})
TARGET_LINK_LIBRARIES(gtatxd PUBLIC ${LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(gtatxd PUBLIC ${INCLUDES})

INSTALL(TARGETS gtatxd DESTINATION bin)

